package CI.aufgabe2.cip.mynodes;

import CI.aufgabe2.cip.SymbolTable;
import CI.aufgabe2.cip.base.AbstractDescr;
import CI.aufgabe2.cip.descriptor.SimpleTypeDescr;

	public class MyFieldListNode extends MyAbstractNode {

		private static final long serialVersionUID = 1L;

		private final MyIdentListNode identList;
		private final MyAbstractNode type;
		
		public MyFieldListNode(MyIdentListNode identList, MyAbstractNode type) {
			this.type=type;
			this.identList=identList;
		}

		@Override
		public void print() {
			trace("FieldListNode ");
			if(identList != null) {
				identList.print();
			}
			if(type != null) {
				type.print();
			}
			unindent();
			
		}
		
		
		public AbstractDescr compile(SymbolTable sym) {
			AbstractDescr descr = null;
			if(type instanceof MyIdNode){
				String s = ((MyIdNode) type).strval;
				if(s.equals("integer")){
					descr = new SimpleTypeDescr(s);
				}
				else if(s.equals("string")){
					descr = new SimpleTypeDescr(s);
				}
				else{
					descr = sym.getDescr(s);
				}
			}else{
				descr = type.compile(sym);
			}
			identList.compile(sym, descr);
			return null;
		}
		
}
